package leetcode.simple._previous;

//最大子数组的和，动态规划
public class MaxSubArray {

    public int maxSubArray(int[] nums) {

        int max = nums[0];
        int curMax = nums[0];

        for (int i = 1; i < nums.length; i++) {
            if (max + nums[i] > nums[i]) {
                max += nums[i];
            }else max = nums[i];

            curMax = Math.max(max,curMax);
        }
        return curMax;
    }
}
